<?php

/*
 * This file is part of the Geek-Zoo Projects.
 *
 * @copyright (c) 2010 Geek-Zoo Projects More info http://www.geek-zoo.com
 * @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License
 * @author quqiang <quqiang@geek-zoo.com>
 *
 */

require ROOT_PATH.'/Helper/admin_abstract.php';

class Action extends admin_abstract
{
    function index()
    {
	
	    $q = _GET('q');
	    if(addslashes($q)){
		    $like = " where name LIKE '%$q%' && type='0' ";
	    } else {
	     $like = "where type='0'";
	    }
	    $data = _model('filt_key')->getList($like.'order by id', new Pager(20));
	$this->view->assign($data);
	$this->view->assign($data);    
        $this->view->display('admin/filt_list.html');
    }


    function add()
    {
    
    	$this->view->display('admin/filt_add.html');
    
    }

    function insert()
    {

	    $name = _POST('t_name');
	    $check_name= _model('filt_key')->read(array('name'=>$name));
	
	    if($check_name){
	    
	    	$this->msg('关键词已存在!');
	    }
	    if(!empty($name)){
	   
	    $id = _model('filt_key')->create(array('name'=>$name));
    		
		    if($id){
	    
		    	$this->msg('添加成功', 'admin/filt_key.html');
		    }else{
	    
		    	$this->msg('添加失败');
		    }
    	
	
    	    }
    
    }

    function mod(){

	    $id = _GET('id', 0);

		if($id){
			$msg = _model('filt_key')->read(array('id'=>$id));	
			$this->view->assign('msg', $msg);
		}
    	$this->view->display('admin/filt_mod.html');
    }

    function update(){
    
    	 $id = _POST('id', 0);
	 $name = _POST('t_name');  	
	 if(!$id){
	 
		 $this->msg('信息不完整');	    
	    
	 }

	 if(empty($name)){
	 
	 	$this->msg('不能为空!');
	 }
	 $check_name= _model('filt_key')->read(array('name'=>$name));

	 if($check_name && $id!=$check_name['id']){
	    
	    	$this->msg('关键词已存在!');
	 }
	    	_model('filt_key')->update(array('id'=>$id), array('name'=>$name));
	    	$this->msg('关键词修改成功', 'admin/filt_key.html');
    	
    
    }

    function delete(){


	    $id = _GET('id', 0);
	    if($id){
	   _model('filt_key')->delete(array('id'=>$id));
	
	    }
	    $this->redirect('admin/filt_key.html');
    
    }

    function alldel(){
	    $arr = _POST('ids', array());

	    foreach($arr as $val){
	    
		    _model('filt_key')->delete(array('id'=>$val));
	    }
	    $this->redirect('admin/filt_key.html');
    }
}


?>
